﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public abstract class WebBaseRoot : System.Web.UI.Page
{

    public WebBaseRoot()
    {

    }
    protected override void OnInit(System.EventArgs e)
    {
        BuildPage(GenerateHtmlForm());
        base.OnInit(e);
    }
    private void BuildPage(HtmlForm form)
    {
        AddHead();
        this.Controls.Add(form);
        AddTail();
    }
    protected virtual HtmlForm GenerateHtmlForm()
    {
        HtmlForm form = new HtmlForm();
        AddLogo();
        AddControlsFromDerivedPage(form);
        //AddRunTimeControls(form);
        AddImage();
        AddMenu();
        AddContent();
        AddFooter();
        return form;
    }
    private void AddHead()
    {
        this.Controls.AddAt(0, new LiteralControl(@"
          <html xmlns='http://www.w3.org/1999/xhtml' >
            <head runat='server'>
                <title>Sync Home Page</title>
                <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
                <style type='text/css'></style>
                <link href='css/css1.css' rel='stylesheet' type='text/css' />
            </head>
            <body align='center'>
            "));
    }

    private void AddTail()
    {
        this.Controls.Add(new LiteralControl(@"
            </body>
            </html>
            "));
    }
    protected virtual void AddLogo()
    {
        this.Controls.Add(new LiteralControl(@"
            <img src= '" + GlobalVar.imageLogo +@"' width='80' height='80' class='logo'>
            "));
    }
    private void AddControlsFromDerivedPage(HtmlForm form)
    {
        int count = this.Controls.Count;
        for (int i = 0; i < count; ++i)
        {
            System.Web.UI.Control ctrl = this.Controls[0];
            form.Controls.Add(ctrl);
            this.Controls.Remove(ctrl);
        }
    }
    protected abstract void AddMenu();
    protected abstract void AddImage();
    protected abstract void AddContent();
    protected abstract void AddFooter();
    //protected abstract void AddRunTimeControls(HtmlForm form);
}